from conn import mongo_client

db = mongo_client.bigdata

col_infos = []

total = 0
for col in db.list_collection_names():
    cur_stat = db.command("collStats", col)
    # size_in_bytes = cur_stat.get("size", 0)
    size_in_bytes = cur_stat.get("storageSize", 0)
    size_in_gb = size_in_bytes / (1024**3)  # 将字节转换为 GB
    cnt = db[col].estimated_document_count()
    if cnt > 0:
        col_infos.append(dict(name=col, size=size_in_gb, cnt=cnt))
    total += size_in_gb
